<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-09-22 10:26:19
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-10-03 17:10:32
 * @Description: 
 * 
-->
<template>
  <el-dialog  draggable overflow v-model="visible" :title="'修改客户名称'" :width="700" destroy-on-close @closed="$emit('closed')">

    <sk-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-form :model="form" ref="dialogForm" label-width="70px">
          <el-row :gutter="40" justify="space-evenly">

            <el-col :span="24">
              <sc-form-table ref="table" v-model="form" :addTemplate="addTemplate" placeholder="无收款数据" hideAdd
                style="height:185px;overflow-y: auto;background:">
                <el-table-column prop="time" label="收款金额" width="100">
                  <template #default="scope">
                    <el-input v-model="scope.row.amount"></el-input>
                  </template>
                </el-table-column>
                <el-table-column prop="type" label="收款银行卡" width="100">
                  <template #default="scope">
                    <sk-select-group v-model="scope.row.subject_id" :list="accountList"
                      @select="(data) => subjectSelect(data, scope.row)" />
                  </template>
                </el-table-column>
                <el-table-column prop="val" label="收款日期" width="100">
                  <template #default="scope">
                    <el-date-picker v-model="scope.row.billdate" type="date" placeholder="选择收款日期"
                      value-format="YYYY-MM-DD" />
                  </template>
                </el-table-column>
                <el-table-column prop="val" label="摘要" width="250">
                  <template #default="scope">
                    <el-input v-model="scope.row.summary"></el-input>
                  </template>
                </el-table-column>


              </sc-form-table>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </sk-tabs>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skSelectGroup from "@/components/skSelectGroup";
import XEUtils from "xe-utils";
export default {
  emits: ["success", "closed"],
  components: { skSelectGroup },
  data() {
    return {
      form: [],
      addTemplate: {
        billdate: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
        state: 1,
        trade_id: 0
      },
      accountList: [],
      visible: false,
      company_id: 0,
      isSaveing: false,
    };
  },

  mounted() { this.getAccount() },
  methods: {
    //显示
    open() {
      this.visible = true;
      return this;
    },
    subjectSelect(data, row) {
      row.trade_id = data.trade_id;
      //盘点是否有票
      if (data.trade_id == 1000) {
        row.tax_id = 0;
      }
      else {
        row.tax_id = 1;
      }

      if (typeof row.billdate == 'undefined')
        row.billdate = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.finance.debtor.saveList.post({ collection: this.form, company_id: this.company_id });
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },
    async getCollection(id) {
      let res = await this.$API.finance.debtor.list.get({ filter: [{ 'company_id': id }, { 'status_id': 0 }] });
      if (res.code == 200) {
        this.form = res.data.rows;
      }
    },
    getAccount() {
      this.$API.basedata.subject.list.get({ filter: [{ parent_id: 1002 }] }).then((res) => {
        this.accountList = res.data;
      });
    },
    //表单注入数据
    async setData(data) {
      this.company_id = data.id;
      await this.getCollection(data.id)
    },
  },
};
</script>
<style></style>
